package com.api.shopapi.mapper;

import com.api.shopapi.entity.OrderGoodsPrice;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface OrderGoodsPriceMapper {

    @Insert("insert into order_goods_price (OrderGoodsPriceCode,OrderGoodsCode,Price,GoodsSizeCode,GoodsSizeName,GoodsColorCode,GoodsColorName) " +
            "values (#{orderGoodsPrice.OrderGoodsPriceCode},#{orderGoodsPrice.OrderGoodsCode},#{orderGoodsPrice.Price}," +
            "#{orderGoodsPrice.GoodsSizeCode},#{orderGoodsPrice.GoodsSizeName},#{orderGoodsPrice.GoodsColorCode},#{orderGoodsPrice.GoodsColorName})")
    int insert(@Param("orderGoodsPrice") OrderGoodsPrice orderGoodsPrice);

    @Update("update order_goods_price set OrderGoodsCode=#{orderGoodsPrice.OrderGoodsCode},Price=#{orderGoodsPrice.Price},GoodsSizeCode=#{orderGoodsPrice.GoodsSizeCode}," +
            "GoodsSizeName=#{orderGoodsPrice.GoodsSizeName},GoodsColorCode=#{orderGoodsPrice.GoodsColorCode},GoodsColorName=#{orderGoodsPrice.GoodsColorName} " +
            "where OrderGoodsPriceCode=#{orderGoodsPrice.OrderGoodsPriceCode}")
    int update(@Param("orderGoodsPrice") OrderGoodsPrice orderGoodsPrice);

    @Delete("delete from order_goods_price where OrderGoodsPriceCode=#{orderGoodsPriceCode}")
    int delete(@Param("orderGoodsPriceCode") String orderGoodsPriceCode);

    @Select("select * from order_goods_price where OrderGoodsPriceCode=#{orderGoodsPriceCode} limit 1")
    OrderGoodsPrice getByOrderGoodsPriceCode(@Param("orderGoodsPriceCode") String orderGoodsPriceCode);

    @Select("select * from order_goods_price where OrderGoodsCode=#{orderGoodsCode} limit 1")
    OrderGoodsPrice getByOrderGoodsCode(@Param("orderGoodsCode") String orderGoodsCode);

    @Select("select * from order_goods_price")
    List<OrderGoodsPrice> getList();

    @Select("<script>" +
            "select  * from order_goods_price where 1=1  " +
            " <if test ='goodsSizeName !=null and goodsSizeName!=\"\" '>" +
            "  and GoodsSizeName like concat('%',#{goodsSizeName},'%')  " +
            " </if>" +
            " <if test ='goodsColorName !=null and goodsColorName!=\"\" '>" +
            "  and GoodsColorName like concat('%',#{goodsColorName},'%')  " +
            " </if>" +
            "</script> ")
    List<OrderGoodsPrice> getPageList(@Param("goodsSizeName") String goodsSizeName,@Param("goodsColorName") String goodsColorName);
}
